// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

// 自定义指令
import directives from './directives'
Vue.use(directives)

import './assets/less/common.less'
import 'animate.css'

// 登录页面canvas动画图

// Vuex
import store from './store'

// 引入element-ui
import ElementUI,{Message} from 'element-ui'

// , { Row, Col, Menu, Submenu, MenuItem, MenuItemGroup, Dropdown, DropdownMenu, DropdownItem, Card, Form, FormItem, Input } 
import 'element-ui/lib/theme-chalk/index.css'
// Row, Col, Menu, SubMenu, MenuItem, MenuItemGroup
// Vue.component(Row.name, name)
// Vue.component(Col.name, name)
// Vue.component(Menu.name, name)
// Vue.component(Submenu.name, name)
// Vue.component(MenuItem.name, name)
// Vue.component(MenuItemGroup.name, name)
// Vue.component(Dropdown.name, name)
// Vue.component(DropdownMenu.name, name)
// Vue.component(DropdownItem.name, name)
// Vue.component(Card.name, name)
// Vue.component(Form.name, name)
// Vue.component(FormItem.name ,name)
// Vue.component(Input.name, name)


Vue.use(ElementUI)

// 导入axios封装好的插件
import HttpAxios from './http'
Vue.use(HttpAxios)

function formatSeconds(value) { 
  var Hours = Math.floor(value/1000/60/60)
  var minutes = Math.floor(value/1000/60%60)
  var seconds = Math.floor(value/1000%60)
  var result = '登录信息将会在   '+Hours+'小时'+minutes+'分'+seconds+'秒   之后过期!'
  return result
} 

// 如果token过期了就退出，且清空数据(后台设置token过期时间为两小时)
if( store.state.user.adminInfo.token_exp && Date.now() > store.state.user.adminInfo.token_exp*1000 ){
  store.dispatch('user/removeUserInfo').then(()=>{
    router.push({
      path: '/login'
    })
  })
}else{
  setTimeout(()=>{
    Message({
      type: 'warning',
      message: formatSeconds(store.state.user.adminInfo.token_exp*1000-Date.now())
    })
  },1200)
}
// console.log(store.state.user.adminInfo.access_token)

if(store.state.user.adminInfo.access_token){
  // Vue.prototype.$http.getSystemRoute().then((res) => {
  //   console.log(res)
  // })
}

Vue.config.productionTip = false

/* eslint-disable no-new */
var vm = new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

